﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class PostOnline : System.Web.UI.Page
{
    public int News_id;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Submit_Button_Click(object sender, EventArgs e)
    {
        string tableTitle = "ctl00$ContentPlaceHolder$title";
        string tableContent = "ctl00$ContentPlaceHolder$content";
        string tablePublish = "ctl00$ContentPlaceHolder$cbPublish";
        {
            NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
            int catalog_id = 9;
            int news_id = 0;
            News news = new News();
            news.Time = DateTime.Now;
            news.Title = Request.Form[tableTitle];
            news.Content = Request.Form[tableContent];
            news.isPublished = 0;
            news.Checker = 0;
            var UserInfo = from userinfo in dc.UserInfos
                       where userinfo.Group_id.Equals("3")
                       select userinfo;
            foreach (var userinfo in UserInfo)
            {
                news.Editor = userinfo.User_id;
            }
            try
            {
                SQL.SQLHelper.Insert(news);
            }
            catch (Exception ex)
            {
            }

            var News = from pNews in dc.News
                       where pNews.Title.Equals(Request.Form[tableTitle].ToString())
                       select pNews;
            foreach (var pNews in News)
            {
                news_id = pNews.News_id;
            }
            dc.Dispose();

            NewsToCatalog newsToCatalog = new NewsToCatalog();
            newsToCatalog.News_id = news_id;
            newsToCatalog.Catalog_id = catalog_id;

            try
            {
                SQL.SQLHelper.Insert(newsToCatalog);
            }
            catch (Exception ex)
            {
            }

            title.Value = Request.Form[tableTitle];
            content.Value = Request.Form[tableContent];
        }
        Response.Redirect("Default.aspx");
    }
    protected void Return_Button_Click(object sender, EventArgs e)
    {
        this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
    }
}
